package com.yami.shop.app.controller;

import cn.hutool.core.convert.Convert;
import com.yami.shop.app.utils.HttpResult;
import com.yami.shop.bean.app.dto.DeliveryDto;
import com.yami.shop.bean.cashregisterapp.AppCashRegister;
import com.yami.shop.common.util.Json;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.yami.shop.service.AppCashRegisterService;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/app/appCashRegister")
@Api(tags="收银机操作接口")
public class AppCashRegisterController {

    @Autowired
    private AppCashRegisterService appCashRegisterService;

    /**
     * 查看收银机接口
     */
    @PostMapping("/check")
    public HttpResult checkDelivery(){
        List<AppCashRegister> appCashRegisterList = appCashRegisterService.list();
        return HttpResult.success(appCashRegisterList);
    }

    @PostMapping("/addAppCashRegister")
    @ApiOperation(value = "添加收银机设备",notes = "添加")
    public HttpResult addAppCashRegister(AppCashRegister appCashRegister){
        appCashRegister.setCreateTime(new Date());
        appCashRegisterService.save(appCashRegister);
        return HttpResult.success(appCashRegister);
    }

    @PostMapping("/deleteAppCashRegister")
    @ApiOperation(value = "删除收银机设备",notes="删除")
    public HttpResult deleteAppCashRegister(String ids){
        String[] idsString = ids.split(",",-1);
        List<Long> idsLong = new ArrayList<>();
        for(String id : idsString){
            idsLong.add(Long.valueOf(id));
        }
        appCashRegisterService.deleteCashRegisterByIds(idsLong);
        return HttpResult.success();
    }


}
